package com.racetime.daoImpl;

import com.racetime.dao.UserDao;
import com.racetime.po.User;
import com.racetime.util.JdbcUtil;
import com.racetime.util.MyLogger;

import java.util.List;
import java.util.logging.Logger;

/**
 * @author : Ice'Clean
 * @date : 2021-05-21
 */
public class UserDaoImpl implements UserDao {

    Logger servletLogger = MyLogger.getLogger("servlet");

    @Override
    public User findUserById(int userId) {
        List<User> users = JdbcUtil.query("select * from t_user where user_id = ?", User.class, userId);
        return users.size() == 0 ? null : users.get(0);
    }

    @Override
    public User findUserByUserName(String userName) {
        List<User> users = JdbcUtil.query("select * from t_user where user_name = ?", User.class, userName);
        return users.size() == 0 ? null : users.get(0);
    }

    @Override
    public int createNewUser(User user) {
        return JdbcUtil.insert("t_user", user);
    }
}
